<?php
class Business_Feedback
{
    protected $_tableName = "feedback";
	function insert($data)
	{
		$data['ctime'] = $data['mtime'] = date("Y-m-d H:i:s");
		$table = Db_Factory::getInstance()->createTable($this->_tableName);
		return $table->insert($data);
	}
	
	/**
	 * 获取信息反馈列表
	 * @param number $page
	 * @param number $rowCount
	 * @param string $order
	 * @return Ambigous <multitype:, multitype:mixed Ambigous <string, boolean, mixed> >
	 */
	public function get($page = 1, $rowCount = 10, $order = 'mtime DESC')
	{
		$fields = array("id", "title", "content", "tel", "email");
		$select = Db_Factory::getInstance()->createSelect();
		$select->from($this->_tableName, $fields)
		        ->order($order)
		        ->limitPage($page, $rowCount);
		$stmt = $select->query();
		$result = $stmt->fetchAll();
		return $result;
	}
	
	/**
	 * 获得信息反馈总数
	 * @return Integer
	 */
	public function getAmount()
	{
		$select = Db_Factory::getInstance()->createSelect();
		$select->from($this->_tableName, "count(*) as count");
		$stmt = $select->query();
		$result = $stmt->fetch();
		$count = isset($result['count']) ? $result['count'] : 0;
		return $count;
	}
	
	/**
	 * 删除记录
	 * @param Integer $id
	 * @return number
	 */
	public function delete($id)
	{
		$id = intval($id);
		$where = array("id = ?" => $id);
		$table = Db_Factory::getInstance()->createTable($this->_tableName);
		return $table->delete($where);
	}
}